package com.example.administrator.yuejian35.Recommend.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.yuejian35.Club.bean.Course;
import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.Recommend.model.RecommendModel;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.example.administrator.yuejian35.Config.Img_URL;

public class CourseinfoActivity extends AppCompatActivity {
   /* private Course course;*/
   private TextView course_name;
    private TextView course_intro;
    private TextView course_notice;
    private TextView course_time;
    private ImageView ic_back;
    private TextView course_price;
    private TextView course_degree;
    private ImageView shangla_pic;
    private ImageView course_pic;
    private Button apply_button;
    private String courseId;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_courseinfo);
        course_name = (TextView) findViewById(R.id.course_name);
        course_intro = (TextView) findViewById(R.id.course_intro);
        course_notice = (TextView) findViewById(R.id.course_notice);
        course_time = (TextView) findViewById(R.id.course_time);
        course_degree= (TextView) findViewById(R.id.course_degree);
        course_price = (TextView) findViewById(R.id.course_price);
        shangla_pic = (ImageView) findViewById(R.id.shangla_pic);
        course_pic = (ImageView) findViewById(R.id.video_pic);
        ic_back = (ImageView) findViewById(R.id.master_pi);
        apply_button = (Button) findViewById(R.id.apply_button);

        courseId = getIntent().getStringExtra("courseid");
        apply_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(CourseinfoActivity.this,CourseApplyActivity.class);
                intent.putExtra("courseid",courseId);
                CourseinfoActivity.this.startActivity(intent);
            }
        });

        ic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        RecommendModel recommendmodel = new RecommendModel();
        Call call = recommendmodel.getcourse(courseId);

        call.enqueue(new Callback<Course>() {

            @Override
            public void onResponse(Call<Course> call, Response<Course> response) {
               // Toast.makeText(CourseinfoActivity.this,response.body().getCoursename().toString(),Toast.LENGTH_SHORT).show();
                course_name.setText(response.body().getCoursename());
                if(response.body().getDegree().equals("1")){
                    course_degree.setText("菜鸟级");
                }
                else if(response.body().getDegree().equals("3")){
                    course_degree.setText("进阶级");
                }
                else{
                    course_degree.setText("入门级");
                }
                course_intro.setText("课程简介："+response.body().getCourseintro());
                course_notice.setText("课程须知："+response.body().getNotice());
                course_time.setText("上课时间："+response.body().getCoursetime());
                course_price.setText("￥"+response.body().getPrice());

                shangla_pic.setOnClickListener(new View.OnClickListener() {
                    Boolean flag = true;
                    @Override
                    public void onClick(View view) {

                        if (flag) {
                            flag = false;
                            course_intro.setEllipsize(null);// 展开  
                            course_intro.setSingleLine(flag);
                            shangla_pic.setImageResource(R.drawable.ic_shangla);
                            //Toast.makeText(CourseinfoActivity.this,"展开",Toast.LENGTH_SHORT).show();

                            }else{
                            flag=true;
                            course_intro.setEllipsize(TextUtils.TruncateAt.END);// 收缩  
                            course_intro.setSingleLine(true);
                            shangla_pic.setImageResource(R.drawable.ic_xiala);
                            //Toast.makeText(CourseinfoActivity.this,"收缩",Toast.LENGTH_SHORT).show();
                            }
                    }
                });
                Picasso.with(CourseinfoActivity.this)
                        .load(Img_URL+response.body().getCoursepic())
                        .into(course_pic);
            }

            @Override
            public void onFailure(Call<Course> call, Throwable t) {
                Toast.makeText(CourseinfoActivity.this,"22222222", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
